/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calculator;

import hibernate.entityes.Distance;
import result.ResultCalculation;

/**
 *
 * @author eleven
 */
public class DistanceTableCalculator implements DistanceTable {

    @Override
    public ResultCalculation calculate(String fromCity, String toCity) {
        dao.DistanceDAOImpl daodistance = dao.DAOFactory.getHibernateDAOFactory().getDistanceDAOImpl();
        Distance distance = daodistance.getDistanceByFromCityToCity(fromCity, toCity);
        ResultCalculation result = new ResultCalculation(fromCity,
                toCity,
                getType(),
                Double.NaN);
        if (distance != null) {
            result.setResult(distance.getDistance());
        }
        return result;
    }

    @Override
    public TypeCalculator getType() {
        return new TypeCalculator("Distance Table Calculator");
    }
}
